<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Section 6.7.&nbsp; Other Data Files</title>
<link rel="STYLESHEET" type="text/css" href="images/style.css">
<link rel="STYLESHEET" type="text/css" href="images/docsafari.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch06lev1sec6.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch06lev1sec8.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
<br><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><a name="ch06lev1sec7"></a>
<h3 class="docSection1Title">6.7. Other Data Files</h3>
<p class="docText">We've discussed only two of the system's data files so far: the password file and the group file. Numerous other files are used by UNIX systems in normal day-to-day operation. For example, the BSD networking software has one data file for the services <a name="idd1e44001"></a><a name="idd1e44006"></a><a name="idd1e44011"></a><a name="idd1e44016"></a><a name="idd1e44021"></a><a name="idd1e44026"></a><a name="idd1e44031"></a><a name="idd1e44036"></a><a name="idd1e44041"></a><a name="idd1e44046"></a><a name="idd1e44049"></a><a name="idd1e44054"></a><a name="idd1e44059"></a><a name="idd1e44064"></a><a name="idd1e44067"></a><a name="idd1e44072"></a>provided by the various network servers (<tt>/etc/services</tt>), one for the protocols (<tt>/etc/protocols</tt>), and one for the networks (<tt>/etc/networks</tt>). Fortunately, the interfaces to these various files are like the ones we've already described for the password and group files.</P>
<p class="docText">The general principle is that every data file has at least three functions:</P>
<div style="font-weight:bold"><ol class="docList" type="1"><li><div style="font-weight:normal"><p class="docList">A <tt>get</tt> function that reads the next record, opening the file if necessary. These functions normally return a pointer to a structure. A null pointer is returned when the end of file is reached. Most of the <tt>get</tt> functions return a pointer to a <tt>static</tt> structure, so we always have to copy it if we want to save it.</P></div></LI><LI><div style="font-weight:normal"><p class="docList">A <tt>set</tt> function that opens the file, if not already open, and rewinds the file. This function is used when we know we want to start again at the beginning of the file.</p></div></LI><LI><div style="font-weight:normal"><p class="docList">An <tt>end</tt> enTRy that closes the data file. As we mentioned earlier, we always have to call this when we're done, to close all the files.</p></div></LI></ol></div>
<p class="docText">Additionally, if the data file supports some form of keyed lookup, routines are provided to search for a record with a specific key. For example, two keyed lookup routines are provided for the password file: <tt>getpwnam</tt> looks for a record with a specific user name, and <tt>getpwuid</tt> looks for a record with a specific user ID.</p>
<p class="docText"><a class="docLink" href="#ch06fig06">Figure 6.6</a> shows some of these routines, which are common to UNIX systems. In this figure, we show the functions for the password files and group file, which we discussed earlier in this chapter, and some of the networking functions. There are <tt>get</tt>, <tt>set</tt>, and <tt>end</tt> functions for all the data files in this figure.</P>
<a name="ch06fig06"></a><P><table cellspacing="0" class="allBorders" border="1" RULES="groups" cellpadding="5"><caption><H5 class="docTableTitle">Figure 6.6. Similar routines for accessing system data files</h5></caption><colgroup><col width="80"><col width="100"><col width="80"><col width="80"><col width="160"></colgroup><thead><TR><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="bottom"><p class="docText"><span class="docEmphRoman">Description</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="bottom"><p class="docText"><span class="docEmphRoman">Data file</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="bottom"><p class="docText"><span class="docEmphRoman">Header</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="bottom"><p class="docText"><span class="docEmphRoman">Structure</span></P></th><th class="bottomBorder thead" scope="col" align="center" valign="bottom"><p class="docText"><span class="docEmphRoman">Additional keyed lookup functions</span></p></th></tr></thead><tr><td class="rightBorder" align="left" valign="top"><p class="docText">passwords</P></td><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>/etc/passwd</tt></p></TD><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>&lt;pwd.h&gt;</tt></p></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>passwd</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getpwnam</tt>, <tt>getpwuid</tt>
</p></td></tr><tr><td class="rightBorder" align="left" valign="top"><p class="docText">groups</p></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>/etc/group</tt></p></td><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>&lt;grp.h&gt;</tt></P></td><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>group</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getgrnam</tt>, <tt>getgrgid</tt>
</P></TD></TR><tr><TD class="rightBorder bottomBorder" align="left" valign="top"><p class="docText">shadow</p></TD><TD class="rightBorder bottomBorder" align="left" valign="top"><p class="docText"><tt>/etc/shadow</tt></P></td><TD class="rightBorder bottomBorder" align="left" valign="top"><p class="docText"><tt>&lt;shadow.h&gt;</tt></P></td><TD class="rightBorder bottomBorder" align="left" valign="top"><p class="docText"><tt>spwd</tt></P></td><td class="bottomBorder" align="left" valign="top"><p class="docText"><tt>getspnam</tt>
</p></td></TR><tr><TD class="rightBorder" align="left" valign="top"><p class="docText">hosts</p></TD><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>/etc/hosts</tt></p></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>&lt;netdb.h&gt;</tt></p></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>hostent</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>gethostbyname</tt>, <tt>gethostbyaddr</tt>
</p></td></tr><tr><td class="rightBorder" align="left" valign="top"><p class="docText">networks</p></td><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>/etc/networks</tt></P></td><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>&lt;netdb.h&gt;</tt></P></TD><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>netent</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getnetbyname</tt>, <tt>getnetbyaddr</tt>
</p></TD></tr><TR><TD class="rightBorder" align="left" valign="top"><p class="docText">protocols</P></td><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>/etc/protocols</tt></P></td><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>&lt;netdb.h&gt;</tt></P></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>protoent</tt></p></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getprotobyname</tt>, <tt>getprotobynumber</tt>
</p></TD></tr><TR><td class="rightBorder" align="left" valign="top"><p class="docText">services</p></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>/etc/services</tt></p></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>&lt;netdb.h&gt;</tt></p></td><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>servent</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getservbyname</tt>, <tt>getservbyport</tt>
</p></td></tr></table></p><BR>
<blockquote>
<p class="docText">Under Solaris, the last four data files in <a class="docLink" href="#ch06fig06">Figure 6.6</a> are symbolic links to files of the same name in the directory <tt>/etc/inet</tt>. Most UNIX System implementations have additional functions that are like these, but the additional functions tend to deal with system administration files and are specific to each implementation.</P>
</blockquote>

<ul></UL></TD></TR></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch06lev1sec6.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch06lev1sec8.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
</body></html><br>
<table width="100%" cellspacing="0" cellpadding="0"
style="margin-top: 0pt; border-collapse: collapse;"> 
<tr> <td align="right" style="background-color=white; border-top: 1px solid gray;"> 
<a href="http://www.zipghost.com/" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">The CHM file was converted to HTM by Trial version of <b>ChmD<!--240-->ecompiler</b>.</a>
</TD>
</TR><tr>
<td align="right" style="background-color=white; "> 
<a href="http://www.etextwizard.com/download/cd/cdsetup.exe" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">Download <b>ChmDec<!--240-->ompiler</b> at: http://www.zipghost.com</a>
</TD></tr></table>
